import { Space, Switch } from 'antd';
import React from 'react';
import { useModel } from 'umi';
import Avatar from './AvatarDropdown';
import styles from './index.less';

export type SiderTheme = 'light' | 'dark';

const GlobalHeaderRight: React.FC = () => {
  const { initialState, setInitialState } = useModel('@@initialState');

  if (!initialState || !initialState.settings) {
    return null;
  }

  const { navTheme, layout } = initialState.settings;
  let className = styles.right;

  if ((navTheme === 'realDark' && layout === 'top') || layout === 'mix') {
    className = `${styles.right}  ${styles.dark}`;
  }
  return (
    <Space className={className}>
      <Avatar />
      <Switch
        checkedChildren={'🌙'}
        unCheckedChildren={'☀'}
        checked={initialState.settings.navTheme === 'realDark'}
        onChange={(checked) => {
          setInitialState((preInitialState) => ({
            ...preInitialState,
            settings: {
              ...preInitialState?.settings,
              navTheme: checked ? 'realDark' : 'light',
            },
          }));
        }}
      />
    </Space>
  );
};
export default GlobalHeaderRight;
